#include "worldobject.h"
#include <QDebug>
#include <string>

int WorldObject::nextID = 0;

//moves a WorldObject based on its velocity
void WorldObject::move()
{
    x = x + xVelocity;
    y = y + yVelocity;
}

//switches the XVelocity of an object
void WorldObject::switchXVelocity() {
    if (xVelocity > 0)
    {
        xVelocity *= (-1);
        x -= 8;
    }
    else
    {
        xVelocity *= -1;
        x += 8;
    }

}

//switches the XVelocity of an object
void WorldObject::switchYVelocity() {
    if (yVelocity > 0)
    {
        yVelocity = yVelocity * (-1);
        x -= 8;
    }
    else
    {
        yVelocity *= -1;
        y += 8;
    }
}

//Changes the sign of either the X component or Y component of a WorldObject, depending on the value of the input parameter
void WorldObject::bounce(int value)
{
    if (value == 1)
    {
        switchXVelocity(); //method in WorldObject that flips the sign of XVelocity
    }
    else if (value == 2)
    {
        switchYVelocity(); //method in WorldObject that flips the sign of YVelocity
    }
}

//Cycles through PacMan's eating frames in endless loop.  Returns file path to new frame every time it is called.
void PacMan::updateImage()
{
    if (imgframe < 37)
        imgframe += 5;  //Go every 5 frames to make PacMan eat faster, but still eventually use all frames
    if(imgframe >= 37)
        imgframe -= 37;
    image = ":/images/PacMan/" + to_string(imgframe) + "-PacMan.png";
}

WorldObject* PacMan::load()
{
    return NULL;
}

WorldObject* Ghost::load()
{
    return NULL;
}

WorldObject* Paddle::load()
{
    return NULL;
}

WorldObject* Wall::load()
{
    return NULL;
}

WorldObject* Dot::load()
{
    return NULL;
}

void WorldObject::movePaddle()
{
    //max paddle yVelocity is 30
    if (yVelocity > 30)
    {
        yVelocity = 30;
    }
    else if (yVelocity < -30)
    {
        yVelocity = -30;
    }
    else if (yVelocity != 0)
    {
        yVelocity = (double)29/32*yVelocity;
    }

    //update position of paddle
    y = y + yVelocity;

    //make sure paddle is not off of the screen
    if (y < 0)
    {
        y = 0;
        yVelocity = 0;
    }
    else if (y > 520)
    {
        y = 520;
        yVelocity = 0;
    }
}

//Increments the Y velocity of given WorldObject
void WorldObject::incYVelocity(int incY)
{
    yVelocity = yVelocity + incY;
}

